package com.studor.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.studor.common.Result;
import com.studor.entity.Dormitory;
import com.studor.service.DormitoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/dormitory")
public class DormitoryController {
    
    @Autowired
    private DormitoryService dormitoryService;
    
    @GetMapping("/list")
    @SaCheckLogin
    public Result<List<Dormitory>> list() {
        List<Dormitory> dormitories = dormitoryService.list();
        return Result.success(dormitories);
    }
    
    @PostMapping("/add")
    @SaCheckLogin
    public Result<Void> add(@RequestBody Dormitory dormitory) {
        dormitoryService.save(dormitory);
        return Result.success("添加宿舍楼成功");
    }
    
    @PutMapping("/update")
    @SaCheckLogin
    public Result<Void> update(@RequestBody Dormitory dormitory) {
        dormitoryService.updateById(dormitory);
        return Result.success("更新宿舍楼成功");
    }
    
    @DeleteMapping("/delete/{dormitory}")
    @SaCheckLogin
    public Result<Void> delete(@PathVariable String dormitory) {
        dormitoryService.removeById(dormitory);
        return Result.success("删除宿舍楼成功");
    }
}